package org.demo.five;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.security.Provider;
import java.security.Security;

import org.junit.Test;

/**
 * 
 * @author  
 * @date    2010-10-24
 * @file    org.demo.five.PersonTest.java
 */
public class PersonTest {
	
	@Test public void getPrivoder(){
		Provider[] pvs = Security.getProviders();
		for (Provider p : pvs){
			System.out.println(p.getName());
		}
	}
	@Test public void serializeToDist(){
		try {
			Person boy = new Person("A","a",22);
			Person girl = new Person("B","b",20);
			boy.setSpouse(girl);
			girl.setSpouse(boy);
			// 
			FileOutputStream fos = new FileOutputStream("d:\\Temp\\p.ser");
			ObjectOutputStream out = new ObjectOutputStream(fos);
			out.writeObject(boy);
			out.close();
			fos.flush();
			fos.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	@Test public void unserializeFromDisk(){
		try {
			FileInputStream fis = new FileInputStream("d:\\Temp\\p.ser");
			ObjectInputStream in = new ObjectInputStream(fis);
			Person boy = (Person)in.readObject();
			System.out.println("firstName=" + boy.getFirstName());
			System.out.println("lastName=" + boy.getlastName());
			System.out.println("age=" + boy.getAge());
			System.out.println("spouse=" + boy.getSpouse().getFirstName());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
